package com.punch.user.controller;


import com.punch.common.dto.user.menu.MenuDTO;
import com.punch.common.model.Result;
import com.punch.common.vo.user.menu.MenuTreeVO;
import com.punch.common.vo.user.menu.SimpleMenuTreeVO;
import com.punch.user.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * MenuController-菜单表 前端控制器
 *
 * @author wujj
 * @version 1.0.0
 * @since 2020/6/3 18:23
 */
@RestController
@Api(value = "SysMenuController", tags = "菜单管理Controller")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 菜单树
     *
     * @return List<MenuTreeVO>
     */
    @ApiOperation(value = "菜单树")
    @GetMapping(value = "/menus")
    public Result<List<MenuTreeVO>> treeMenu() {
        return Result.succeed(menuService.treeMenu());
    }


    /**
     * 简单菜单树,用于角色选择菜单
     *
     * @return List<MenuTreeVO>
     */
    @ApiOperation(value = "简单菜单树,用于角色选择菜单")
    @GetMapping(value = "/menus/simple")
    public Result<List<SimpleMenuTreeVO>> treeSimpleMenu() {
        return Result.succeed(menuService.treeSimpleMenu());
    }

    /**
     * 新增菜单
     */
    @PostMapping("/menu")
    @ApiOperation(value = "新增菜单")
    public Result<Long> saveMenu(@RequestBody MenuDTO menuDTO) {
        return Result.succeed(menuService.saveMenu(menuDTO));
    }


    /**
     * 修改菜单
     */
    @PutMapping("/menu")
    @ApiOperation(value = "修改菜单")
    public Result<Long> updateMenu(@RequestBody MenuDTO menuDTO) {
        return Result.succeed(menuService.updateMenu(menuDTO));
    }

    /**
     * 删除菜单
     */
    @DeleteMapping("/menu/{menuId}")
    @ApiOperation(value = "删除菜单")
    public Result<Long> deleteMenu(@PathVariable Long menuId) {
        return Result.succeed(menuService.deleteMenu(menuId));
    }
}
